package main.java.com.rmisorter;

import java.awt.List;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Random;

@SuppressWarnings({"rawtypes", "unused"})
public class SortClient {
	private final int NUMBEROFRANDOMITEMS = 100, NUMBEROFLISTS = 4;
	private final String SORTER = "InsertionSort", GENERATEMETHOD = "generateRandomInteger";
	private ListHandler listHandler;
	public static void main(String[] args) throws Exception {
		new SortClient();
	}
	
	public SortClient() throws Exception {
		this.listHandler = new ListHandler();
		sort();
	}
	
	public void sort() throws Exception {
		Comparable[] list = this.listHandler.generateRandomList(NUMBEROFRANDOMITEMS, GENERATEMETHOD);
		Comparable[][] lists = this.listHandler.splice(list, NUMBEROFLISTS);
		int iThread = 1;
		ListJoiner listJoiner = new ListJoiner(NUMBEROFRANDOMITEMS, NUMBEROFLISTS);

		for(Comparable[] listPart : lists) {
			SorterThread sorterThread = new SorterThread(listPart, iThread, SORTER, listJoiner);
			sorterThread.start();
			iThread++;
		}
	}
}
